#include "Draw.h"

// ------------------------------------------------------------------
void Draw::drawLine( const Vetor2d& p1, const Vetor2d& p2 )
{
    glBegin(GL_LINES);
        glVertex2f(p1.x, p1.y);
        glVertex2f(p2.x, p2.y);
    glEnd();
}
// ------------------------------------------------------------------
void Draw::drawArc( const Vetor2d& pos,
                    float radius,
                    float startAngle,
                    float delta,
                    unsigned int steps )
{
    glPushMatrix();
        glTranslatef(pos.x, pos.y, 0.0f);
        glBegin(GL_TRIANGLE_FAN);
            glVertex2f(0.0f, 0.0f);

            for( unsigned int i= 0; i<=steps ; i++ )
            {
                float angle = startAngle + (delta*i/(float)steps);
                float x = radius*cosf( angle*M_PI/180.0f );
                float y = radius*sinf( angle*M_PI/180.0f );
                glVertex2f(x,y);
            }

        glEnd();
    glPopMatrix();
}
// ------------------------------------------------------------------
void Draw::drawCircle( const Vetor2d& pos,
                         float radius,
                         unsigned int pieces )
{
        drawArc( pos, radius, 0.0f, 360.0f, pieces  );
}
// ------------------------------------------------------------------
void Draw::drawEllipse( const Vetor2d& pos,
                         float radiusX,
                         float radiusY,
                         unsigned int pieces )
{
    glPushMatrix();

        glTranslatef( pos.x, pos.y, 0.0f );
        glScalef( radiusX, radiusY, 1.0f );
        glTranslatef( - pos.x, - pos.y, 0.0f);

        drawCircle( pos, 1.0f, pieces );
    glPopMatrix();
}
// ------------------------------------------------------------------
void Draw::drawQuad(void)
{
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,0.0f);        glVertex2f( -1.0f, -1.0f);
        glTexCoord2f(1.0f,0.0f);        glVertex2f( +1.0f, -1.0f);
        glTexCoord2f(1.0f,1.0f);        glVertex2f( +1.0f, +1.0f);
        glTexCoord2f(0.0f,1.0f);        glVertex2f( -1.0f, +1.0f);
    glEnd();
}
// ---------------------------------------------------------------

